package com.ruoyi.kanfang.util;

import com.ruoyi.common.core.domain.AjaxResult;
import lombok.extern.slf4j.Slf4j;

/**
 * @description:
 * @author limin
 * @date 2024-05-10
 */
@Slf4j
public class BizProxy {


    public static AjaxResult execute(BizFunction bizFunction){
        try {
            Object obj = bizFunction.execute();

            return AjaxResult.success(obj);
        } catch (BusinessException e){
            log.error("Biz:{}",e.getErrorMessage());
            return AjaxResult.warn(e.getErrorMessage());
        }catch (Exception e) {
            log.error("unknown:{}",e);
            return AjaxResult.error(e.getMessage());
        }
    }

    @FunctionalInterface
    public interface BizFunction<T>{
        T execute();
    }
}
